package io.kimmking.common.rocketmq.repository;

import io.kimmking.common.rocketmq.base.BaseIConsumer;
import io.kimmking.dubbo.common.unit.ThrowableActionV2;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.beans.factory.annotation.Value;

import java.util.List;

/**
 * 消费者示例
 */
@Slf4j
//@RocketMQMsgListener(
//        //下边可以去掉，都使用的是默认值
//        consumeMode = ConsumeMode.CONCURRENTLY, //默认值，并发接收模式
//        messageModel = MessageModel.CLUSTERING, //默认值，集群模式
//        selectorType = SelectorType.TAG, // 默认值，标签
//        selectorExpression = "*" //默认值，匹配该topic下所有tag
//)
public class ConsumerWrapper extends BaseIConsumer<Object> {

    /**
     * 自定义需要消费的topic及group
     */
    @Value("{}")
    private String topic;

    @Value("{}")
    private String cosumer_group;

    @Override
    public ConsumeConcurrentlyStatus consumeMessage(final List<MessageExt> msgs,
                                             final ConsumeConcurrentlyContext context){
        //todo,
        return null;
    }

    /**
     * 对消费到的消息进行拦截处理(如果需要的话)
     * @param msgs
     */
    @Override
    protected void handle(List<MessageExt> msgs) {
        ThrowableActionV2.execute(() -> {
            //todo..

        });
    }

}